Skip to content

ricursive cuda: structured output and forced tool calls for Ripple-65B-Preview - #5363

Draft
jrb-ai wants to merge 5 commits into
ashhart:mainfrom
jrb-ai:ricursive-cuda-structures
Draft

jrb-ai wants to merge 5 commits into
ashhart:mainfrom
jrb-ai:ricursive-cuda-structures

Conversation

@jrb-ai

@jrb-ai jrb-ai commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Before, Ripple-65B-Preview on CUDA refused response_format, the guided_* and structured_outputs fields and a
forced tool call (tool_choice "required" or a named function) with HTTP 400: the CUDA ricursive backend had no
first_masked, and it refused a grammar stream and a masked verify window. After, it serves them. A grammar's rows
are copied on the device, tf_grammar_mask puts the copy's disallowed tokens at -inf, and the draw and argmax
kernels of a row with no grammar draw from the copy. Logprob rows read the model's own rows, as on Metal.

A request with no grammar runs the launches it ran before, and the backend allocates the bytes it allocated before:
the scratch for the copies and the mask bits (27.3 MB) is opened by the first grammar row. A mask of the wrong
length is refused by name before the forward.

Checks on this head

  • Head commit: 1f475e66d. The GB10 build, the family suites, the plain dumps and the served checks ran on
    7facf77cc, this PR's second commit. The head adds three commits to it: the contract case (test files and one
    control kernel in contract_controls' image; no served kernel and no backend line), one recipe sentence and the
    changelog line's PR number. The contract case ran on GB10 in ricursive: Ripple-65B-Preview's DFlash2 drafter on native CUDA #2475's tree (1353bbd55), which holds this PR's
    first four commits unchanged. A run of the head alone follows; the recipe's SUMMARY line is from 7facf77cc
    until then (see Kernel contract). The Mac suite ran on 7facf77cc; the host test, the Linux compile and the
    checkers below ran on 577aa2eb5, which the head differs from by the changelog line.
  • Lean checker on the base and on this head: 123 and 123, 0 new (tools/zig/lean_new.py). tools/pr_check.py --base 2713f2791 --pr 5363 on the head: 0 errors. zig fmt --check build.zig zig and git diff --check: clean.
    tools/zig/cuda_common_check.py: 0 violations; tools/zig/cuda_fragment_check.py: 0 misses.
  • Tests, Mac (M5 Pro), zig build test test-kernel-contract test-golden -Dcpu=apple_m1 from an empty cache, on
    7facf77cc: 1,158 of 1,163 steps; 18,999 of 19,155 tests pass, 153 skip, 3 fail. The base 2713f2791 gives the
    same result on this Mac but for this PR's one host test (18,998 of 19,154; 153 skip; the same 3 fail): two
    Inkling 2 Metal tests ("Mini pre-fusion skips only visit 0 ..." and "48-visit Inkling 2 Mini Metal verify tree
    ...") and "info prices a Qwen3.8-27B start from serve's charge ...", and the same failed build step (lfm3's
    tests, "no module named 'rope_freq'"). zig build test-ricursive-cuda-host: 42 of 42. The Linux binaries and
    GPU tests compile from the Mac on the head (zig build compile-cuda-tests compile-cuda-cli native -Dtarget=aarch64-linux-gnu): 25 of 25 steps.
  • Tests, GB10, tf-cuda-test on 7facf77cc: ripple-serve 13 passed, 0 failed, with check 7's four lines (below);
    ripple-forward 35 and 0; ricursive-contract 20 kernels pass gates 1-4, 0 fail, 24 controls red as planted, 0
    missed.
  • CI: see the checks on this page; I classify any failure in a comment.
  • Not run, and why: chips other than GB10 (no hardware). Every family's kernel contract and the five-SM limits: no
    served kernel is new or changed; the one new launch is tf_grammar_mask at 256 threads, a block a row, which the
    registry holds as "sample tf_grammar_mask". tools/bench_concurrent.py and tools/bench_openai.py: see Receipt
    for what ran in their place.

Receipt

  • Main against branch: the plain engine's logits are bit-identical on all 2,586 rows of the recipe's chat, for
    prompt chunks of 2,048 and 333 rows and for one-row decode, against the reference dumps that main gives too
    (main e63912221 on 26 Nov; this branch at 7facf77cc on 27 Nov); the 256-token greedy run's token hash is
    equal.
  • Boxes it reaches: GB10 (DGX Spark). Not run on any other.
  • New switch? None.
  • Environment: TensorFold main 2713f2791 and this branch, Zig 0.17.0, CUDA 13 (nvcc 13.3, V13.3.73), DGX Spark
    (GB10, sm_121, 121.7 GiB shared with the host), ricursiveAI/Ripple-65B-Preview-NVFP4 at
    99eea4477a001a41b86914e41feb4b2ed86105e5, --context 32768. libtfgrammar from the 1.2.2 release archive (the
    server logs "structured output: xgrammar over 100352 tokens"). Mac: M5 Pro, 48 GB.
  • Paths and platforms the change reaches: the CUDA ricursive backend's first draw and verify windows of a stream
    with a grammar. A stream with no grammar takes the branch it took before (mask.len == 0, w.masks.len == 0).
    Metal, the lane core, the grammar window and the server are not changed. Run: sm_121. Not run: sm_80, 86, 89, 120.
  • Exactness, the gates named on Ripple-65B (ricursive) on CUDA: structured output and forced tool calls #5252, GPU tests on the release-width fixture (ripple-serve check 7, greedy and
    sampled at temperature 1, top-p 0.95, top-k 20):
    • Masked draws against the same sampler over an independent masked copy: a stream's first token and a 4-row
      verify window under masks (every token allowed, about half, five tokens, all but the plain draw's token) each
      equal the plain draw over the same row with its disallowed tokens at -inf. A greedy draw also equals the first
      largest allowed logit, picked on the host.
    • Raw-logit logprob words: the model's rows under masks equal the same window's rows with no mask, byte for byte,
      and each logprob row equals a float64 log-softmax of the unmasked row (ids exact, values within 2e-6).
    • Mixed and unmasked streams unchanged: streams with no grammar in rounds beside a masked stream give 8 draws and
      their logits each, equal to each stream alone.
    • A mask of the wrong length is refused by name (InvalidGrammarMasks) before the forward.
    • Plain dumps unchanged: see "Main against branch".
  • Exactness at the server, on 7facf77cc (the recipe's served checks, 157 requests): 11 request forms
    (response_format json_object and json_schema; guided_json, guided_regex, guided_choice, guided_grammar;
    structured_outputs json, json_object, regex, choice, grammar), each greedy and sampled (seed 7): 44 requests,
    every reply valid for its form, each equal to its repeat. Tool calls with tool_choice "auto", "required"
    and a named function, and a streamed required call: all call the function with JSON arguments, and the streamed
    arguments equal the reply sent whole. On main the same script gets HTTP 400 for the 11 forms and for both forced
    choices (run on 26 Nov). The other served checks pass unchanged (seeded repeats, 60 repeats of a reply,
    streaming, multi-turn resumes, stop strings, max_tokens, verbatim copies, logprob rows): 10 pass, 0 fail, 1
    skipped (the long-prompt check, which needs a token file).
  • Several structured requests at once (the plain server of ricursive: Ripple-65B-Preview's DFlash2 drafter on native CUDA #2475's tree, which holds this PR's first four commits unchanged):
    8 structured requests, greedy and sampled, each alone, then 2 at once, then 8 at once: 36 replies, each valid for
    its form and equal to the same request alone.
  • With the drafter of ricursive: Ripple-65B-Preview's DFlash2 drafter on native CUDA #2475 (its integration branch, 1353bbd55, stacked on this PR; not part of this PR), on GB10:
    • A --drafter server against this PR's plain server: 157 of 157 requests of the served checks equal by status,
      finish reason and reply hash, 44 structured and 5 tool requests among them. On the structured requests 233 of
      499 drafts were accepted (386 tokens in 135 rounds, against 402 tokens in 376 rounds with "draft": false).
    • Accepted drafts under a grammar at 1, 2 and 8 streams: the 8 structured requests above on the --drafter
      server, alone, 2 at once and 8 at once. Every reply equals the plain server's, and the server's log shows 158
      of 339, 42 of 89 and 149 of 365 drafts accepted at the three levels.
  • Decode speed before and after: the CLI's 256-token greedy run at one stream, 247.954 ms a token on main
    e63912221 (26 Nov) and 248.201 ms on 7facf77cc (27 Nov; 247.726 ms on this PR's first form the same morning).
    tools/bench_openai.py was not run: a request with no grammar runs the same launches as on main.
  • Prompt speed before and after: n/a. The prompt pass is not changed; its logits are bit-identical (above).
  • Licence of any new weights or drafter: n/a.
Kernel contract
  • Kernels registered with the contract, and the kernel each one replaces: tf_grammar_mask (sample.cu, a kernel
    main already serves; its launch record "sample tf_grammar_mask" is unchanged) joins ricursive-contract as the
    backend launches it: 256 threads, a block a row, the family's vocabulary, at 1, 3, 7, 16 and 128 rows and at the
    tile's edges. It replaces none. Its rule: an allowed token keeps its bits, NaN patterns included; a disallowed
    token is -inf, word for word.
  • A planted control for each new kernel, and each one fails as planted: tf_ctl_rc_grammar_mask
    (contract_controls' image) reads token t at bit 31 - t % 32 of its word. It is red at the shapes gate, as
    planted ("at 128x100352x1: row 0 token 2: c0b0 where ff80 is due").
  • Each backend's SUMMARY line and exit status: CUDA (GB10), exit 0, in ricursive: Ripple-65B-Preview's DFlash2 drafter on native CUDA #2475's tree (1353bbd55), which has two
    kernels and three controls of its own beside this PR's:
    SUMMARY ricursive: 23 kernels, 23 pass gates 1-4, 0 fail; 28 controls: 28 red as planted, 0 missed
    The mask's lines: nonfinite PASS (the stated rule holds), repeat PASS (five runs byte-identical, 12,845,056
    bytes), shapes PASS (9 shapes exact, 0 edges refused), sums n/a. On 7facf77cc, before the case:
    SUMMARY ricursive: 20 kernels, 20 pass gates 1-4, 0 fail; 24 controls: 24 red as planted, 0 missed
  • Chips I could not run: everything except GB10.

Checklist

  • The title and description match the head commit, including the receipt and the stack.

  • New tests fail before the change, pass after it, and skip cleanly without their dependency. (The GPU checks
    and the host test do not build on main, which has no first_masked and no maskWords; the served script gets
    HTTP 400 on main. The mask's contract case passes on main too: the kernel is main's.)

  • Comments and docstrings are one line. No measurements or history in the source.

  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.

  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off.

  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (The
    first and the third hold under a grammar, as measured above. A resumed prompt under a grammar was not measured;
    without a grammar the multi-turn check passes unchanged.)

  • No precision traded for speed. If the bits change, the description says which sums change and why.

  • Decode and prompt processing are no slower than main at one stream and the widest admitted; with --drafter, no slower than without it, greedy and sampled (One stream: 247.954 ms a token on main, 248.201 ms here, inside the
    day's spread of 247.7 to 248.3. Eight streams were not timed; a request with no grammar runs main's launches.)

Authored by JRB AI in a private capacity. This contribution does not represent the views or positions of any organisation.

…rows drawn under its mask on the GPU

Ripple's CUDA backend had no first_masked, and it refused a grammar stream when it opened and a masked
window in verify, so the server reported no structured output for the model (ashhart#5252). The lane core, the
grammar window and the server need no change.

A grammar's rows are copied on the device (a scratch of a round's rows and their bits, 27.3 MB, opened by
the first such row), sample.cu's tf_grammar_mask puts the copy's disallowed tokens at -inf, and the draw
and argmax kernels of a row with no grammar draw from the copy. Greedy rows stay on the device: the
argmax kernel orders raw bits and takes -inf as the lowest value. The logprob rows read the model's own
rows, as on Metal. A row with no grammar runs the launches it ran before, and init allocates the bytes it
allocated before.

A mask of the wrong length is refused by name (InvalidGrammarMasks) before the forward. The kernel
contract holds the launch already (sample tf_grammar_mask, 256 threads).

ripple-serve check 7 (GB10, ripple_mask_tests.zig): the first token and a 4-row window under masks (every token, about half,
five tokens, all but the plain one), greedy and sampled, each draw against the plain draw over the same
row with the other tokens at -inf; the model's rows and logprob rows against those with no mask; streams
with no grammar in rounds beside a masked stream against each alone. test-ricursive-cuda-host: the words
of a grammar row; the family words no refusal for structured output now.

Fixes ashhart#5252.
…alls, as run on GB10

ripple-serve check 7 and the served forms on e1dc05998: the masked draws against the plain draw over
the rows with the other tokens at -inf, 11 request forms greedy and sampled, and tool calls by
tool_choice auto, required, a named function and a streamed required call. The plain dumps are
bit-identical to the 6 November reference's (refs ashhart#5252).
…s, and a control that reads a word's bits from the top

ricursive-contract takes sample.cu's tf_grammar_mask as the backend launches it (256 threads, a block a row,
the family's vocabulary) at 1, 3, 7, 16 and 128 rows and at the tile's edges: an allowed token keeps its
bits, NaN patterns included, and a disallowed token is -inf, word for word. The planted control,
tf_ctl_rc_grammar_mask in contract_controls' image, reads token t at bit 31 - t % 32 and must turn the
shapes gate red. No served kernel and no launch record changes (refs ashhart#5252).
The backend serves logprob rows (the first token's, a round's and a prompt's); only a thinking budget is
refused by name (refs ashhart#5252).
@ashhart

ashhart commented Nov 27, 2026

Copy link
Copy Markdown
Owner

Thank you, @jrb-ai. This looks safe for a runtime A/B.

Masked draws keep allowed BF16 values and original logprob rows intact; unmasked requests keep their old path.
Compare token IDs on GB10/sm_121 with your pinned Ripple checkpoint, covering mixed rounds and required/named calls.
It merges cleanly on main.

  • Synthena

ashhart pushed a commit to jrb-ai/TensorFold that referenced this pull request Nov 28, 2026
jrb-ai added a commit to jrb-ai/TensorFold that referenced this pull request Nov 28, 2026
jrb-ai added a commit to jrb-ai/TensorFold that referenced this pull request Nov 28, 2026
jrb-ai added a commit to jrb-ai/TensorFold that referenced this pull request Nov 28, 2026
ashhart pushed a commit to jrb-ai/TensorFold that referenced this pull request Nov 29, 2026
ashhart pushed a commit to jrb-ai/TensorFold that referenced this pull request Nov 29, 2026
ashhart pushed a commit to jrb-ai/TensorFold that referenced this pull request Nov 30, 2026
ashhart pushed a commit to jrb-ai/TensorFold that referenced this pull request Nov 30, 2026
ashhart pushed a commit to jrb-ai/TensorFold that referenced this pull request Nov 30, 2026
ashhart pushed a commit to jrb-ai/TensorFold that referenced this pull request Nov 30, 2026
jrb-ai added a commit to jrb-ai/TensorFold that referenced this pull request Dec 2, 2026
jrb-ai added a commit to jrb-ai/TensorFold that referenced this pull request Dec 2, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ripple-65B (ricursive) on CUDA: structured output and forced tool calls

2 participants